package com.dream.controller;

import com.dream.pojo.VisitRecord;
import com.dream.service.VisitRecordService;
import com.dream.service.impl.VisitRecordServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Date;

@WebServlet("/VisitRecordController.do")
public class VisitRecordController extends BaseServlet{
    VisitRecordService visitRecordService = new VisitRecordServiceImpl();

    public void add(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
        String stuId = request.getParameter("stuId");
        String stuTemp = request.getParameter("stuTemp");
        String dormitoryId = request.getParameter("dormitoryId");
        String recordDate = request.getParameter("recordDate");
        VisitRecord visitRecord = new VisitRecord(stuId,stuTemp,Long.valueOf(dormitoryId), Date.valueOf(recordDate));
        int count = visitRecordService.addVisitRecord(visitRecord);
        if (count>0){
            response.getWriter().write("<script>alert('来访登记成功');location.href='visitRegister.jsp';</script>");
        }else {
            response.getWriter().write("<script>alert('来访登记异常');location.href='visitRegister.jsp';</script>");
        }
    }
}
